/****************************************************************/
//unit encompasses player and enemy. It has their stats and shared
//attributes.
// Tyler Wozniak & Andrew Hall
/***************************************************************/


#include "Unit.h"

int Unit::unitCount;

//Default constructor
Unit::Unit( void )
{
	xPos = 1;
	yPos = 1;
	uHash = unitCount;
	unitCount++;
}

//Copy constructor
Unit::Unit(const Unit& u)
{
	this->xPos = u.xPos;
	this->yPos = u.yPos;
	this->health = u.health;
	this->strength = u.strength;
	this->agility = u.agility;
	this->stamina = u.stamina;
	uHash = unitCount;
	unitCount++;
};

//Constructor for taking an X and Y in
Unit::Unit( int x, int y )
{
	xPos = x;
	yPos = y;
	uHash = unitCount;
	unitCount++;
}

//uses modules to play one of 2 sounds for being hit
void Unit::playRandSound()
{
	cout << "Random sound playing" << endl;
	int random = rand();
	if (random % 2 == 0)
	{
		PlaySound(TEXT("../sounds/getHit.wav"), NULL, SND_FILENAME | SND_ASYNC);
		return;
	}
	PlaySound(TEXT("../sounds/gotHit1.wav"), NULL, SND_FILENAME | SND_ASYNC);
}

//accessors
int Unit::getX() const			{ return xPos;		}
int Unit::getY() const			{ return yPos;		}
int Unit::getStr() const		{ return strength;	}
int Unit::getAgi() const		{ return agility;	}
int Unit::getSta() const		{ return stamina;	}
string Unit::getName()const		{ return name;		}
int Unit::currentHealth() const { return health;	}

//subtracts amount of damage and returns whether the player is dead
bool Unit::takeDamage(int amount)
{
	health -= amount;
	return health < 1;
}

//Returns the character to represent this unit type
//Returns a ? because this should always be overridden
Unit::operator char() const
{
	return '?';
}

//The way to check if two units are the same
bool Unit::operator==( const Unit& other ) const
{
	return this->uHash == other.uHash;
}

//Prints the unit's data
void Unit::print( ostream& o ) const
{
	o << "Units are abstract...why you print me?" << endl;
}

//Destructor
Unit::~Unit()
{

}

//Returns the maximum health of a unit
int Unit::maxHealth() const
{
	return stamina * 3 + strength * 2;
}

//Returns whether or not this unit is faster than the other,
//by having a higher efficiency value
bool Unit::operator<( const Unit* other ) const
{
	return this->agility < other->agility;
}

//Returns the chance to hit value for the unit
int Unit::getHit() const
{
	int hit = agility;
	hit += hit / 3;
	return hit;
}

//Returns the chance to dodge attacks
int Unit::getEva() const
{
	int eva = agility;
	eva -= eva / 3;
	return eva;
}


